<?php
/**
 * Created by PhpStorm.
 * User: mr.lee
 * Date: 2018/10/9
 * Time: 11:11 AM
 */

namespace app\apitemp\controller;


use app\common\controller\FeiePrint;
use app\common\model\Agent;
use app\common\model\Merchant;
use app\common\model\Paylog;
use app\common\model\WxOpen;
use think\Controller;
use Wechat\Wxobjopen;

class Index extends Controller
{
    public function test(){
//       $paylog=new Paylog();
//       $map['mid']=501;
//       $map['pay_fs']="3";
//       $orderid=$paylog->where($map)->order('id desc')->value('orderid');
//       $FeiePrint=new FeiePrint();
//       $FeiePrint->sendprint($orderid);
        $postData="你是我的好朋友";
        $encode = mb_detect_encoding($postData, array("ASCII", 'UTF-8', "GB2312", "GBK", 'BIG5'));
//        halt($encode);
echo mb_convert_encoding($postData, "UTF-8", $encode);

    }
    public function test2(){

//        $Pub=new Pub();
//        $service_charge=$Pub->service_charge('501',0.1,"wx_service_charge");

$s=$this->getsubopenid();
halt($s);
    }
    public function getsubopenid()
    {
        $map['id'] = 501;
        $Merchant = new Merchant();
        $Agent = new Agent();
        $WxOpen = new WxOpen();
        $config = $Merchant->where($map)->find();
        $agent = $Agent->where(array('id' => $config['agent']))->find();
        $users = $WxOpen->where(array('id' => $agent['wx_open_id']))->find();
        $options = array(
            'appid' => $users['authorizer_appid'], // 填写高级调用功能的app id
            'partnerid' => $agent['partnerid'], // 财付通商户身份标识
            'partnerkey' => $agent['partnerkey'], // 财付通商户权限密钥Key
        );
        $weObj = new Wxobjopen($options);
        //会员卡支付
        $appid = $WxOpen->where('id', $config['wx_open_id'])->value('authorizer_appid');
        $sparam['appid'] = $users['authorizer_appid'];
        $sparam['sub_appid'] = $appid;
        $sparam['mch_id'] = $agent['partnerid'];
        $sparam['sub_mch_id'] = $config['sub_mch_id'];
        $sparam['auth_code'] = "134614559618427748";
        $getpenid = $weObj->get_open_id($sparam);
        if ($getpenid['return_code'] !== "FAIL" && $getpenid['result_code'] !== "FAIL") {
            $openid = $getpenid['sub_openid'];
        } else {
            $openid = '';
        }
        return $getpenid;
    }

}